package cn.chencq.sort;

import java.util.Arrays;

public class SelectSort {

	public static void sort(int arr[]) {
		int len = arr.length;
		int small, temp;
		int i, j;
		for (i = 0; i < len - 1; i++) {
			small = i;
			for (j = i + 1; j < len; j++) {
				if (arr[j] < arr[small]) {
					small = j;
				}
			}
			if (small != i) {
				temp = arr[i];
				arr[i] = arr[small];
				arr[small] = temp;
			}
			System.out.println(Arrays.toString(arr));
		}
	}

	public static void main(String[] args) {
		int[] arr = { 7,5,2,4,8,2,1,3};
		SelectSort.sort(arr);
	}

}
